package com.ravi.controller;

import com.github.pagehelper.PageInfo;
import com.ravi.common.constant.CheckExceptionEnum;
import com.ravi.model.dto.RoomTypeDto;
import com.ravi.model.query.CommonPageReq;
import com.ravi.model.resp.R;
import com.ravi.service.intf.RoomTypeService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class RoomTypeController {

	@Autowired
	private RoomTypeService roomTypeService;

	// 查看所有的诊室种类
	@PostMapping("/roomType/all")
	public R getAllRoomTypes(@RequestBody CommonPageReq commonPageReq){
		PageInfo<RoomTypeDto> pageInfo = roomTypeService.getRoomTypePage(commonPageReq.getPageNum(), commonPageReq.getPageSize());
		return R.ok().put("pageInfo", pageInfo);
	}

	// 查询某种诊室类型
	@GetMapping("/roomType/search")
	public R searchRoomType(@RequestParam("keyword") String keyword) {
		List<RoomTypeDto> roomTypeSearch = roomTypeService.getRoomTypeSearch(keyword);
		if (ObjectUtils.isEmpty(roomTypeSearch)) {
			return R.error(CheckExceptionEnum.SEARCH_FAILED);
		}else
			return R.ok("查询成功!").put("roomTypes", roomTypeSearch);
	}
}
